<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<%@ include file="/web/head.jsp"%>
</head>
<body>
	<div class="layui-row">
		<div class="layui-col-md10">
			<div class="layui-card" style="height: 140px;">
				<div class="layui-card-header">作品查询和添加</div>
				<div class="layui-card-body" style="margin-top: 20px;">
					<form class="layui-form">
						<div class="layui-form-item">
							<!-- 题目 -->
							<div class="layui-inline">
								<label class="layui-form-label">题目</label>
								<div class="layui-input-inline" style="width: 150px;">
									<input type="text" name="title" placeholder="请输入题目"
										autocomplete="off" class="layui-input">
								</div>
								<div class="layui-form-mid">关键字</div>
								<div class="layui-input-inline" style="width: 150px;">
									<input type="text" name="key" placeholder="请输入关键字"
										autocomplete="off" class="layui-input">
								</div>
								<div class="layui-form-mid">作者</div>
								<div class="layui-input-inline" style="width: 150px;">
									<input type="text" name="author" placeholder="请输入作者"
										autocomplete="off" class="layui-input">
								</div>
								<div class="layui-form-mid">文章类型</div>
								<div class="layui-input-inline">
									<select name="typeId">
									</select>
								</div>
								<div class="layui-form-mid">审查结果</div>
								<div class="layui-input-inline" style="width:100px;">
									<select name="result">
										<option value="">不限</option>
										<option value="notfind">未审查</option>
										<option value="pass">仅通过</option>
										<option value="notpass">仅未通过</option>
									</select>
								</div>
							</div>
							<div class="layui-inline">
								<input class="layui-btn ayui-btn-radius layui-btn-sm" lay-submit
									lay-filter="search" value="搜索" style="width: 50px;" /> <input
									type="reset"
									class="layui-btn ayui-btn-radius layui-btn-primary layui-btn-sm"
									value="重置" /> <input type="button"
									class="layui-btn layui-btn layui-btn-sm" value="添加" />
							</div>
						</div>
						<input type="hidden" name="pageIndex" value="1"><input
							type="hidden" name="pageLimit" value="8"> <input
							type="hidden" name="action" value="get">
					</form>
				</div>
			</div>
		</div>
		<div class="layui-col-md2" style="height: 150px;">
			<div class="layui-card" style="height: 140px;">
				<div class="layui-card-header">类型管理</div>
				<div class="layui-card-body" align="center"
					style="margin-top: 20px;">
					<input type="button" class="layui-btn layui-btn layui-btn"
						value="类型管理" />
				</div>
			</div>
		</div>
	</div>
	<!-- 	table -->
	<div style="margin-top: 0px;">
		<table class="layui-table">
			<thead>
				<tr>
					<th>序号</th>
					<th>题目</th>
					<th>关键字</th>
					<th>类型</th>
					<th>作者</th>
					<th>内容</th>
					<th>时间</th>
					<th>备注</th>
					<th>审查结果</th>
					<th>操作</th>
				</tr>
			</thead>
			<tbody>
			</tbody>
		</table>
		<div id="test1" style="text-align: right; padding-right: 30px;"></div>
	</div>

	<script type="text/javascript">
		formOnSubmit('search', 'json', '/ArticleServlet', function(data) {
			var curr = $('input[name="pageIndex"]').val()
			var limit = $('input[name="pageLimit"]').val()
			// 渲染
			laypage.render({
				elem : 'test1',
				count : data.count,
				layout : [ 'count', 'prev', 'page', 'next', 'limit', 'refresh',
						'skip' ],
				curr : curr,
				limit : limit,
				limits : [ 8, 10, 12, 20 ],
				jump : function(obj, first) {
					$('input[name="pageIndex"]').val(obj.curr)
					$('input[name="pageLimit"]').val(obj.limit)
					if (!first) {
						refresh();
					}
				}
			});
			// 显示
			var html = "";
			var tpl = $('#tradd').html();
			$.each(data.list, function(i, dom) {
				var d = {
					id : i + 1 + (curr - 1) * limit,
					account:dom.id,
					title : dom.title,
					key : dom.key,
					author : dom.author,
					key : dom.key,
					time : dom.time,
					message : dom.message,
					fileName : dom.fileName,
					url : dom.url,
					type : dom.type,
					result:dom.result=="pass"?"<text style='color:red;'>通过</text>": dom.result== null?"未审查":"未通过"
				}
				html += laytpl(tpl).render(d)
			})
			$('tbody').html(html)
		})

		//		添加
		function openType() {
			layerOpen('管理文章类型', '/web/manager/articleType.jsp', '600px',
					'640px', refresh)
		}

		function openAdd() {
			layerOpen('添加文章', '/web/manager/articleAdd.jsp', '480px', '640px',
					refresh)
		}
		
		function updata(id) {
			layerOpen('修改文章', '/web/manager/articleUpdata.jsp?id='+id, '480px', '640px',
					refresh)
		}
		
		function checkList(id,title){
			layerOpen('《'+title+'》的审查记录', '/web/manager/examine.jsp?id='+id, '600px', '400px',
					refresh)
		}
		
		function check(id,title){
			layerOpen('对《'+title+'》添加新的的审查记录', '/web/manager/exmainAdd.jsp?id='+id, '480px', '480px',
					refresh)
		}

		function refresh() {
			$('input[value="搜索"]').click()
		}
		
		refresh();
		
		function del(account) {
			layer.confirm("您确定要删除吗?", {
				title : false,
				closeBtn : 0
			}, function() {
				ajax('/ArticleServlet', 'text', {
					id : account,
					action : "del"
				}, function(data) {
					if (data == 'success') {
						layer.msg('删除成功', {
							time : 1000
						}, function() {
							refresh()
						})
					}
				})
			})
		}

		ajax('/ArticleTypeServlet', 'json', {
			action : 'getAll'
		}, function(res) {
			var html = '<option value="">请选择类型 可输入</option>'
			$.each(res, function(i, dom) {
				html += '<option value="'+dom.id+'">' + dom.name + '</option>'
			})
			$('select[name="typeId"]').html(html)
			form.render('select')
		})

		$('input[value="类型管理"]').click(openType);
		$('input[value="添加"]').click(openAdd);
		
	</script>
	<script type="text/html" id="tradd">
		<tr>
			<td>{{d.id}}</td>
			<td>{{d.title}}</td>
			<td>{{d.key}}</td>
			<td>{{d.type}}</td>
			<td>{{d.author}}</td>
			<td>{{d.fileName}}</td>
			<td>{{d.time}}</td>
			<td>{{d.message}}</td>
			<td>{{d.result}}</td>
			<td>
				<a href="javascript:del('{{d.account}}');" class="layui-btn layui-btn-danger layui-btn-sm">删除</a>
				<a href="javascript:updata('{{d.account}}');" class="layui-btn layui-btn-sm">修改信息</a>
				<a href="/word/{{d.url}}" target = "_blank" class="layui-btn layui-btn-sm">查看文件</a>
				<a href="javascript:check('{{d.account}}','{{d.title}}');" class="layui-btn layui-btn-sm">审查</a>
				<a href="javascript:checkList('{{d.account}}','{{d.title}}');" class="layui-btn layui-btn-sm">审查记录</a>
			</td>
		</tr>
</script>
</body>
</html>